import request from "./request";
import type {news_data,opliset,Datum,childDatum,likeDatum} from '@/type/news'
import type {ac,frientDatum,findDatas,lisac} from '@/type/friend'
import type{List, pageNoticePersonDate}  from '@/type/notice'
import type{userData}  from '@/type/user'
import type{AllUser}  from '@/type/admin'
import type{organizationData}  from '@/type/organization'

interface requesta<T ={}>{
    code?:number,
    data:T
    [key:string]:any
}
type PromiseReq<T>=Promise<requesta<T>>
interface user{
    id:number,
    name:string,
    imageUrl:string
}


/**
 * 用于获取文章的请求
 */
export const newsList=<T>(data:T):PromiseReq<news_data>=>{
    return request({
        url:'/message/pageMessage',
        method:'post',
        data
    })
}

/**
 * 获取分类数据接口
 */
export const optionsList=():PromiseReq<opliset[]>=>{
    return request({
        url:"/message/findKind",
        method:'get',
    })
}

/**
 * 账号号登录
 */
export const loginByAccount=<T>(data:T):PromiseReq<user>=>{
    return request({
        url:'/user/loginByAccount',
        method:'post',
        data
    })
}
/**
 * 获取图片验证码
 */
export const getloginImg=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/user/getCaptchaImg?phone='+data,
        method:'get',
    })
}
/**
 * 获取手机验证码
 */
export const getPhoneCode=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/user/getPhoneCode',
        method:'post',
        data
    })
}
/**
 * 手机号登录
 */
export const Phonelogin=<T>(data:T):PromiseReq<user>=>{
    return request({
        url:'/user/loginByPhone',
        method:'post',
        data
    })
}

/**
 * 获取第一层评论
 * @returns 
 */
export const parentComment=<T>(id:T):PromiseReq<Datum[]>=>{
    return request({
        url:'/comment/parentComment?messageId='+id,
        method:'get',
    })
}

export const childComment=<T>(id:T):PromiseReq<childDatum[]>=>{
    return request({
        url:'/comment/childComment?commentId='+id,
        method:'get',
    })
}

/**
 * 发送评论
 */
export const sendComment=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/comment/sendComment',
        method:'post',
        data
    })
}

/**
 * 删除评论
 */
export const deleteComment=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/comment/deleteComment?commentId='+data,
        method:'DELETE',
    })
}

/**
 * 获取好友列表
 */
export const friends=<T>(data:T):PromiseReq<ac[]>=>{
    return request({
        url:'/userLinkUser/showChats?keyword='+'',
        method:'get',
    })
}
/**
 * 给文章点赞
 */
export const likeMessage=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/message/likeMessage?messageId='+data,
        method:'get',
    })
}

/**
 * 取消点赞
 */
export const deletLike=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/message/cancelLikeMessage?messageId='+data,
        method:'DELETE',
    })
}


/**
 * 获取好友近20条聊天数据
 */
export const showRecentNews=<T>(userId:T):PromiseReq<frientDatum[]>=>{
    return request({
        url:'/news/showRecentNews?userId='+userId,
        method:'get',
    })
}

export const updateReadStatus=<T>(userId:T):PromiseReq<string>=>{
    return request({
        url:'/news/updateReadStatus?userId='+userId,
        method:'put',
    })
}

/**
 * 分页展示通知信息（需要处理的）
 */
export const pageNoticePerson=<T>(data:T):PromiseReq<pageNoticePersonDate>=>{
    return request({
        url:'/notice/pageNoticePerson',
        method:'post',
        data
    })
}
/**
 * 分页展示通知信息（自己发布的）
 */
export const pageNotice=<T>(data:T):PromiseReq<pageNoticePersonDate>=>{
    return request({
        url:'/notice/pageNotice',
        method:'post',
        data
    })
}


/**
 * 展示可通知的用户（按层级展示）
 */
export const showUser=<T>(userId:T):PromiseReq<any>=>{
    return request({
        url:'/notice/showUser?organizationId='+userId,
        method:'get',
    })
}

/**
 * 发布通知
 */
export const sendNotice=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/notice/sendNotice',
        method:'post',
        data
    })
}

/**
 * 修改通知
 * @param data 
 * @returns 
 */
export const updateNotice=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/notice/updateNotice',
        method:'put',
        data
    })
}
/**
 * 确认通知
 * @param data 
 * @returns 
 */
export const acceptNotice=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/notice/acceptNotice?noticeId='+data,
        method:'put',
      
    })
}
/**
 * 删除通知
 * @param data 
 * @returns 
 */
export const deleteNotice=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/notice/deleteNotice?noticeId='+data,
        method:'DELETE',
      
    })
}

/**
 * 获取个人资料
 */
export const showUserMessage=():PromiseReq<userData>=>{
    return request({
        url:'/user/showUserMessage',
        method:'get',
    })
}
/**
 * 修改密码
 * @param data 
 * @returns 
 */
export const updateUserMessage=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/user/updateUserMessage',
        method:'put',
        data
    })
}


/**
 * 获取所有用户
 */
export const showAllUser=<T>(data:T):PromiseReq<AllUser>=>{
    return request({
        url:'/user/showAllUser',
        method:'post',
        data
    })
}

/**
 * 重置密码
 * @param data 
 * @returns 
 */
export const resetPassword=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/user/resetPassword?userId='+data,
        method:'put',
    })
}
/**
 * 批量删除用户
 * @param data 
 * @returns 
 */
export const deleteUser=<T>(Data:T):PromiseReq<string>=>{
    return request({
        url:'/user/deleteUser?userIdList='+Data,
        method:'DELETE',
    })
}
/**
 * 修改组织名称
 * @param data 
 * @returns 
 */
export const updateOrganization=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/organization/updateOrganization',
        method:'PUT',
        data
    })
}


/**
 * 新增组织
 */
export const insertOrganization=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/organization/insertOrganization',
        method:'post',
        data
    })
}
/**
 * 批量删除用户
 * @param data 
 * @returns 
 */
export const deleteOrganization=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/organization/deleteOrganization?organizationId='+data,
        method:'DELETE',
    })
}
/**
 * 展示组织详情
 */
export const showDetail=<T>(userId:T):PromiseReq<organizationData>=>{
    return request({
        url:'/organization/showDetail?organizationId='+userId,
        method:'get',
    })
}

/**
 * 修改用户权限
 * @param data 
 * @returns 
 */
export const updateRole=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/organization/updateRole',
        method:'PUT',
        data
    })
}


/**
 * 查找聊天好友
 */
export const findUser=<T>(data:T):PromiseReq<findDatas>=>{
    return request({
        url:'/userLinkUser/findUser',
        method:'post',
        data
    })
}


/**
 *  点赞飙升榜
 */
export const likeSoaring=():PromiseReq<likeDatum[]>=>{
    return request({
        url:'/message/likeSoaring',
        method:'get',
    })
}
/**
 *  点赞总排行
 */
export const likeLeaderboard=():PromiseReq<likeDatum[]>=>{
    return request({
        url:'/message/likeLeaderboard',
        method:'get',
    })
}

/**
 *  新增种类
 */
export const addKind=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/message/addKind?type='+data,
        method:'get',
    })
}

/**
 * 删除种类
 * @param data 
 * @returns 
 */
export const deleteKind=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/message/deleteKind?name='+data,
        method:'DELETE',
    })
}

/**
 * 查找聊天好友
 */
export const picturePreview=<T>(data:T):PromiseReq<string[]>=>{
    return request({
        url:'/message/preview',
        method:'post',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}
/**
 * 发表新闻
 */
export const sendMessage=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/message/sendMessage',
        method:'post',
        data,
   
    })
}
// /**
//  * 删除新闻
//  * @param data 
//  * @returns 
//  */
// export const deleteMessage=<T>(data:T):PromiseReq<string>=>{
//     return request({
//         url:'/message/deleteMessage?messageIds='+data,
//         method:'DELETE',
        
//     })
// }


/**
 * 查看个人文章
 */
export const pagePersonalMessage=<T>(data:T):PromiseReq<news_data>=>{
    return request({
        url:'/message/pagePersonalMessage',
        method:'post',
        data,
   
    })
}

/**
 * 敏感词
 * @param data 
 * @returns 
 */
export const txtImport=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/sensitive_vocabulary/txtImport',
        method:'PUT',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}
/**
 * 撤回消息
 * @param data 
 * @returns 
 */
export const deleteNews=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/news/deleteNews?newsId='+data,
        method:'DELETE',
        
    })
}


/**
 *  用于更新权限的组织
 */
export const listOrganization=():PromiseReq<{id:number;name:string}[]>=>{
    return request({
        url:"/organization/listOrganization?keyword=''",
        method:'get',
    })
}

/**
 * 置顶
 */
export const topUser=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:"/userLinkUser/topUser?userId="+data,
        method:'PUT',
    })
}

/**
 *取消置顶
 */
export const cancelTopUser=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/userLinkUser/cancelTopUser?userId='+data,
        method:'DELETE',
        
    })
}


/**
 * 删除新闻
 * @param data 
 * @returns 
 */
export const deleteMessage=<T>(data:T):PromiseReq<string>=>{
    return request({
        url:'/message/deleteMessage?messageIds='+data,
        method:'DELETE',
        
    })
}


/**
 * 分页展示与好友的所有聊天记录
 */
export const pageNews=<T>(data:T):PromiseReq<lisac>=>{
    return request({
        url:'/news/pageNews',
        method:'post',
        data,
   
    })
}


/**
 *  获取导出用户
 */
export const excelExport=(data:string):PromiseReq<string>=>{
    return request({
        url:"/organization/excelExport?organizationId="+data,
        method:'get',
        responseType: 'blob',
    })
}

/**
 * 前端错误上报
 */
export const addFrontErrorLog=<T>(data:T):PromiseReq<lisac>=>{
    return request({
        url:'/front/addFrontErrorLog',
        method:'post',
        data,
   
    })
}
